Skip to content

Fix SvgSource invariant globalization startup failure#542

Merged
wieslawsoltes merged 2 commits into
masterfrom
codex/fix-svgservice-invariant-globalization
Jun 15, 2026
Merged

Fix SvgSource invariant globalization startup failure#542
wieslawsoltes merged 2 commits into
masterfrom
codex/fix-svgservice-invariant-globalization

Conversation

@wieslawsoltes

Copy link
Copy Markdown
Owner

Summary

Fixes #541 by making SvgService safe to initialize when .NET runs in invariant globalization mode.

The previous SvgService static field eagerly called CultureInfo.GetCultureInfo("en-US"). In invariant globalization mode, named culture lookup throws CultureNotFoundException, which caused the whole SvgService type initializer to fail before an SVG could be loaded. That surfaced through Svg.Controls.Skia.Avalonia as a TypeInitializationException from SvgSource.Load(...).

This change keeps the existing deterministic en-US default for SVG systemLanguage matching, but avoids doing a throwing named-culture lookup during static initialization. If the runtime cannot create the named culture, SvgService falls back to the language tag string for conditional processing while still allowing tests and callers to override s_systemLanguageOverride.

Changes

  • Added a non-throwing culture lookup helper for the default en-US system language.
  • Centralized current system-language tag selection so invariant globalization still resolves the default en-US behavior.
  • Added an invariant-globalization test project for Svg.Controls.Skia.Avalonia.
  • Covered both inline SVG loading and file-path SVG loading through SvgSource.
  • Added coverage that systemLanguage="en-US" still selects the expected branch under invariant globalization.

Validation

  • dotnet format Svg.Skia.slnx --no-restore
  • dotnet build Svg.Skia.slnx -c Release
  • dotnet test Svg.Skia.slnx -c Release
  • dotnet test tests/Svg.Controls.Skia.Avalonia.InvariantGlobalization.UnitTests/Svg.Controls.Skia.Avalonia.InvariantGlobalization.UnitTests.csproj -c Release --filter "FullyQualifiedName~SvgSourceInvariantGlobalizationTests"
  • dotnet test tests/Svg.Model.UnitTests/Svg.Model.UnitTests.csproj -f net10.0 -c Release --no-restore --filter "FullyQualifiedName~SvgConditionalProcessingTests"

@wieslawsoltes wieslawsoltes merged commit 78d8e64 into master Jun 15, 2026
11 checks passed
@wieslawsoltes wieslawsoltes deleted the codex/fix-svgservice-invariant-globalization branch June 15, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Svg.Controls.Skia.Avalonia 12.0.0.12 System.Exception: The type initializer for 'Svg.Model.Services.SvgService' threw an exception

1 participant